import { defineStore } from "pinia";
import { ref } from "vue";

export const useUploadStore = defineStore("upload",() => {
  const uploadedImages = ref([]);
  let backendResponse = ref("");

  const setImages = (images) => {
    uploadedImages.value = images;
  }

  const removeImage = (id) => {
    uploadedImages.value = uploadedImages.value.filter(img => img.id !== id);
    if(uploadedImages.value.length === 0) {
      setResponse("");
    }
  }

  const setResponse = (response) => {
    backendResponse.value = response;
  };

  const clear = () => {
    uploadedImages.value = [];
    backendResponse.value = "";
  };

  return { uploadedImages, backendResponse, setImages, removeImage, setResponse, clear };
},{
  persist: true
})